home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SampleDriverHeader.c
-
- Contains: Sample Driver Header file
-
- Version: xxx put version here xxx
-
- Copyright: © 1997-1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include <Types.h>
- #include <Devices.h>
- #include <DriverServices.h>
- #include <USB.h>
-
-
- #include "SampleDriver.h"
- #include "SampleDriverVersion.h"
-
- extern usbSamplePBStruct mySamplePB;
-
- //------------------------------------------------------
- //
- // This is the driver description structure that the expert looks for first.
- // If it's here, the information within is used to match the driver
- // to the device whose descriptor was passed to the expert.
- // Information in this block is also used by the expert when an
- // entry is created in the Name Registry.
- //
- //------------------------------------------------------
- USBDriverDescription TheUSBDriverDescription =
- {
- // Signature info
- kTheUSBDriverDescriptionSignature,
- kInitialUSBDriverDescriptor,
-
- // Device Info
- 0x0547, // vendor = anchor
- 0x1002, // product = not device specific
- 0, // version of product = not device specific
- 0, // protocol = not device specific
-
- // Interface Info (* I don't think this would always be required...*)
- 0, // Configuration Value
- 0, // Interface Number
- 0, // Interface Class
- 0, // Interface SubClass
- 0, // Interface Protocol
-
-
- // Driver Info
- "\pUSBSampleDriver", // Driver name for Name Registry
- 0, // Device Class (from USBDeviceDefines.h)
- 0, // Device Subclass
- kSampleHexMajorVers,
- kSampleHexMinorVers,
- kSampleCurrentRelease,
- kSampleReleaseStage, // version of driver
-
- // Driver Loading Info
- kUSBProtocolMustMatch+kUSBDoNotMatchInterface+kUSBDoNotMatchGenericDevice // Flags (currently undefined)
- };
-
- USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
- {
- kClassDriverPluginVersion, // Version of this structure
- SampleDriverValidateHW, // Hardware Validation Procedure
- SampleDeviceInitialize, // Initialization Procedure
- SampleInterfaceInitialize, // Interface Initialization Procedure
- SampleDriverFinalize, // Finalization Procedure
- SampleDriverNotifyProc, // Driver Notification Procedure
- };
-
-
- // Hardware Validation
- // Called upon load by Expert
- OSStatus SampleDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
- {
- #pragma unused (device)
- #pragma unused (desc)
-
- return (OSStatus)kUSBNoErr;
- }
-
-
- // Initialization function
- // Called upon load by Expert
- OSStatus SampleDeviceInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
- {
- #pragma unused (busPowerAvailable)
-
- DeviceInitialize(device, pDesc, busPowerAvailable);
- return (OSStatus)kUSBNoErr;
- }
-
-
- // Interface Initialization Initialization function
- // Called upon load by Expert
- OSStatus SampleInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
- {
- #pragma unused (interfacenum)
- #pragma unused (pInterface)
- #pragma unused (pDesc)
- #pragma unused (device)
-
- return (OSStatus)noErr;
- }
-
- // Termination function
- // Called by Expert when driver is being shut down
- OSStatus SampleDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
- {
- #pragma unused (pDesc)
- OSStatus myErr;
-
- USBExpertStatus(theDeviceRef, "\pUSBSampleDriver: Finalize", theDeviceRef);
-
- if (mySamplePB.pipeRef)
- {
- USBExpertStatus(theDeviceRef, "\pUSBSampleDriver: Aborting interrupt pipe", theDeviceRef);
- USBAbortPipeByReference(mySamplePB.pipeRef);
- }
-
- mySamplePB.pb.usbReference = theDeviceRef;
- mySamplePB.pb.pbVersion = kUSBCurrentPBVersion;
- mySamplePB.pb.usbFlags = 0;
- mySamplePB.pb.usbRefcon = 0;
- mySamplePB.pb.usbCompletion = (USBCompletion)-1;
-
- myErr = USBDeallocMem(&mySamplePB.pb);
-
- return (OSStatus)noErr;
- }
-
- OSStatus SampleDriverNotifyProc(UInt32 notification, void *pointer, UInt32 refcon)
- {
- #pragma unused (pointer)
- #pragma unused (notification)
- #pragma unused (refcon)
- return(kUSBNoErr);
- }
-
- void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
- {
- #pragma unused (pDeviceDescriptor)
- static Boolean beenThereDoneThat = false;
-
- USBExpertStatus(device, "\pUSBSampleDriver: Initialize", device);
- if(beenThereDoneThat)
- {
- USBExpertFatalError(device, kUSBInternalErr, "\pSample driver is not reentrant!", 0);
- return;
- }
- beenThereDoneThat = true;
-
- InitParamBlock(device, &mySamplePB.pb);
-
- mySamplePB.deviceRef = device;
-
- mySamplePB.busPowerAvailable = busPowerAvailable;
- mySamplePB.transDepth = 0;
- mySamplePB.retryCount = kSampleRetryCount;
-
- mySamplePB.deviceRef = device;
- mySamplePB.interfaceRef = nil;
- mySamplePB.pipeRef = nil;
-
- mySamplePB.pb.usbRefcon = kFindInterface;
- mySamplePB.pb.usbReference = device;
- mySamplePB.pb.pbLength = sizeof(usbSamplePBStruct);
-
- InitParamBlock(device, &mySamplePB.pb);
- InitiateTransactionProc(&mySamplePB.pb);
- }
-
-